package com.you.atlas.web.place.module.screen;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.CollectService;
import com.you.atlas.biz.place.service.PlaceQueryService;
import com.you.atlas.biz.place.service.PlaceViewService;
import com.you.atlas.biz.place.service.RateService;
import com.you.atlas.biz.place.service.SmallNoteQueryService;
import com.you.atlas.biz.place.vo.PlaceViewVO;
import com.you.common.ibatis.data.DataList;
import com.you.common.webx.AuthContext;
import com.you.place.dal.dao.dataobject.CollectDO;
import com.you.place.dal.dao.dataobject.RateDO;

public class PlaceView {

	@Autowired
	private PlaceViewService placeViewService;

	@Autowired
	private PlaceQueryService placeQueryService;

	@Autowired
	private CollectService collectService;

	@Autowired
	private RateService rateService;

	@Autowired
	private SmallNoteQueryService smallNoteQueryService;

	public void execute(@Param("id") Long id, Context context,
			Navigator navigator, @Param("placeId") Long placeId) {
		if (placeId != null) {
			id = placeId;
		}
		PlaceViewVO placeViewVO = placeViewService.getPlaceViewVO(id);
		if (placeViewVO.getPlaceDO() == null) {
			navigator.redirectTo("placeModule").withTarget("error.vm");
			return;
		}

		context.put("place", placeViewVO.getPlaceDO());
		context.put("photoList", placeViewVO.getPhotoList());
		context.put("photoCount", placeViewVO.getPhotoCount());
		context.put("noteList", placeViewVO.getNoteList());
		context.put("noteCount", placeViewVO.getNoteCount());

		CollectDO collectDO = collectService.findCollect(AuthContext
				.getContext().getMemberId(), id);
		context.put("collectDO", collectDO);

		RateDO rateDO = rateService.findRate(AuthContext.getContext()
				.getMemberId(), id);
		context.put("rateDO", rateDO);

		DataList dataList = placeQueryService.queryByParentId(1, 6, id);
		context.put("dataList", dataList);

		DataList smallNoteList = smallNoteQueryService.queryByUseFul(id, 1, 4);
		context.put("smallNoteList", smallNoteList);
	}
}
